<template>
  <view class='container'>
    <!-- <view class="title sticky-tabs">远程安全评估系统V6.0</view> -->
    <u-gap height="10" bgColor="#f5f5f5"></u-gap>
    <view class="tab">
      <u-tabs :list="list" @click="select"></u-tabs>
    </view>
    <u-gap height="10" bgColor="#f5f5f5"></u-gap>
    <view v-if="activeIndex==0">
      <u-cell-group>
        <u-cell title="资产编号" :value="obj.assetsNo"></u-cell>
        <u-cell title="资产名称" :value="obj.assetsName"></u-cell>
        <u-cell title="保管单位" :value="obj.depository"></u-cell>
        <u-cell title="购置单位" :value="obj.purchase"></u-cell>
        <u-cell title="使用人" :value="obj.user"></u-cell>
        <u-cell title="管理人" :value="obj.depositary"></u-cell>
        <u-cell title="资产来源" :value="obj.source"></u-cell>
        <u-cell title="取得方式" :value="obj.getMode"></u-cell>
        <u-cell title="是否盘点" :value="obj.inventory==1?'已盘点':'未盘点'"></u-cell>
        <u-cell title="制造厂商" :value="obj.manufactor"></u-cell>
        <u-cell title="资产型号" :value="obj.assetsModel"></u-cell>
        <u-cell title="资产形成" :value="obj.assetsFormation"></u-cell>
        <u-cell title="资产价值" :value="obj.inventoryDate"></u-cell>
        <u-cell title="发票">
          <view slot="value" style="width:80%">
            <view v-for="(v,i) in obj.invoice?JSON.parse(obj.invoice):[]" :key="i">
              <!-- <view @click="openFile(v)" style="color:#0d6fb8;text-decoration: underline;">附件{{i+1}}：{{v.name}}</view> -->
              <uni-link :href="v.url" :text="v.name"></uni-link>
            </view>
          </view>
        </u-cell>

      </u-cell-group>
    </view>
    <view v-if="activeIndex==1">
      <u-cell-group>
        <u-cell title="资产大类" :value="obj.assetsClass"></u-cell>
        <u-cell title="资产小类" :value="obj.assetsSubclass"></u-cell>
        <u-cell title="资产属性" :value="obj.attribute"></u-cell>
        <u-cell title="资产状态" :value="obj.state"></u-cell>
        <!-- <u-cell title="数量" :value="obj.account"></u-cell>
        <u-cell title="计量单位" :value="obj.inventoryDate"></u-cell>
        <u-cell title="取得日期" :value="obj.inventoryDate"></u-cell>
        <u-cell title="资产来源" :value="obj.inventoryDate"></u-cell>
        <u-cell title="设备等级" :value="obj.inventoryDate"></u-cell>
        <u-cell title="所属系统" :value="obj.inventoryDate"></u-cell>
        <u-cell title="资产属性" :value="obj.inventoryDate"></u-cell>
        <u-cell title="购置单位" :value="obj.inventoryDate"></u-cell>
        <u-cell title="取得方式" :value="obj.inventoryDate"></u-cell> -->
      </u-cell-group>
    </view>
    <view v-if="activeIndex==2">
      <u-cell-group>
        <u-cell title="工程项目" :value="obj.engineering"></u-cell>
        <u-cell title="设备等级" :value="obj.level"></u-cell>
        <u-cell title="所属系统" :value="obj.system"></u-cell>
        <u-cell title="建筑面积" :value="obj.builtupArea"></u-cell>
        <u-cell title="占用面积" :value="obj.occupiedArea"></u-cell>
        <u-cell title="登账人员" :value="obj.account"></u-cell>
        <u-cell title="公务用车分类" :value="obj.busType"></u-cell>
        <u-cell title="车型" :value="obj.vehicleType"></u-cell>
        <u-cell title="存放地" :value="obj.deposit">
          <view slot="value" style="width: 50%;">
            <view class="deposit">
              <u-input v-model="obj.deposit" border="none" placeholder="请输入" inputAlign="right">
              </u-input>
              <view class="deposit-btn">
                <u-button text="查询" type="primary" style="width:30rpx" @click="inquire(obj.deposit)"></u-button>
              </view>
            </view>
          </view>
        </u-cell>
      </u-cell-group>
    </view>
    <u-picker :show="selectShow" :columns="columns" @cancel="selectShow=false" @close="selectShow=false" @confirm="confirm" keyName="label" closeOnClickOverlay></u-picker>
    <view class="btn">
      <view class="exit" @click="exit">取消</view>
      <view class="save" @click="submit">保存</view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      list: [{
        name: '管理信息',
      }, {
        name: '分类信息',
      }, {
        name: '使用信息',
      }],
      obj: {},
      activeIndex: 0,
      editState: false,
      selectShow: false,
      columns: [],
    };
  },
  onLoad(e) {
    this.$u.api.GetDetils({ objectID: e.id }).then(res => {

      this.obj = res.data
    })
  },
  onShow() {
  },
  methods: {
    select(val) {

      this.activeIndex = val.index
    },
    exit() {
      uni.navigateBack();
    },
    inquire(deposit) {
      this.selectShow = true
      this.$u.api.GetDeposit({ deposit: deposit }).then(res => {
        const data = res.data.map((x) => {
          return {
            id: x,
            label: x
          }
        })
        this.columns = [data]
      })
    },
    confirm(e) {
      this.selectShow = false
      this.obj.deposit = e.value[0].label
    },
    submit() {
      var _this = this
      wx.showModal({
        title: '提示',
        content: '是否确认提交？',
        success(v) {
          var data = {}
          data.assetsInfo = _this.obj
          data.assetsSubs = []
          _this.$u.api.UpdateAsset(data).then(res => {
            if (res.flag) {
              _this.$u.toast('提交成功');

            }
          })
        }
      })
    },
    openFile(v) {
      console.log(v.url, 'v.url')
      uni.downloadFile({
        url: v.url,
        success: function (res) {
          console.log(res, '8')
          var filePath = res.tempFilePath;
          uni.openDocument({
            filePath: filePath,
            showMenu: true,
            success: function (res) {
              console.log('打开文档成功');
            }
          });
        }
      });
      // window.location.href = v.url

    }
  }
};
</script>

<style scoped lang="scss">
.container {
  min-height: 100vh;
  background: #fff;
  padding-bottom: 180rpx;
  .title {
    height: 100rpx;
    line-height: 100rpx;
    font-size: 34rpx;
    text-align: center;
  }
  .tab {
    background: #fff;
    /deep/.u-tabs__wrapper__nav__item {
      width: 33%;
      box-sizing: border-box;
    }
  }
  .deposit {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    .deposit-btn {
      width: 100rpx;
      margin-left: 10rpx;
    }
  }
  .btn {
    font-size: 30rpx;
    display: flex;
    justify-content: space-around;
    background: #f5f5f5;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 30rpx 0;

    .exit {
      width: 335rpx;
      height: 88rpx;
      background-color: #ffffff;
      border-radius: 10rpx;
      color: #666666;
      text-align: center;
      line-height: 88rpx;
    }
    .save {
      width: 335rpx;
      height: 88rpx;
      background-color: #0d6fb8;
      border-radius: 10rpx;
      color: #ffffff;
      text-align: center;
      line-height: 88rpx;
    }
  }
}
.sticky-tabs {
  z-index: 990;
  position: sticky;
  top: var(--window-top);
  background-color: #fff;
}
</style>
